package cn.iocoder.yudao.module.yyzx.controller.admin.nurse_record;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.apilog.core.annotations.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.yyzx.controller.admin.nurse_record.vo.*;
import cn.iocoder.yudao.module.yyzx.dal.dataobject.nurse_record.Nurse_recordDO;
import cn.iocoder.yudao.module.yyzx.service.nurse_record.Nurse_recordService;

@Tag(name = "管理后台 - 护理记录")
@RestController
@RequestMapping("/yyzx/nurse_record")
@Validated
public class Nurse_recordController {

    @Resource
    private Nurse_recordService nurse_recordService;

    @PostMapping("/create")
    @Operation(summary = "创建护理记录")
    @PreAuthorize("@ss.hasPermission('yyzx:nurse_record:create')")
    public CommonResult<Integer> createNurse_record(@Valid @RequestBody Nurse_recordSaveReqVO createReqVO) {
        return success(nurse_recordService.createNurse_record(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新护理记录")
    @PreAuthorize("@ss.hasPermission('yyzx:nurse_record:update')")
    public CommonResult<Boolean> updateNurse_record(@Valid @RequestBody Nurse_recordSaveReqVO updateReqVO) {
        nurse_recordService.updateNurse_record(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除护理记录")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('yyzx:nurse_record:delete')")
    public CommonResult<Boolean> deleteNurse_record(@RequestParam("id") Integer id) {
        nurse_recordService.deleteNurse_record(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得护理记录")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('yyzx:nurse_record:query')")
    public CommonResult<Nurse_recordRespVO> getNurse_record(@RequestParam("id") Integer id) {
        Nurse_recordDO nurse_record = nurse_recordService.getNurse_record(id);
        return success(BeanUtils.toBean(nurse_record, Nurse_recordRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得护理记录分页")
    @PreAuthorize("@ss.hasPermission('yyzx:nurse_record:query')")
    public CommonResult<PageResult<Nurse_recordRespVO>> getNurse_recordPage(@Valid Nurse_recordPageReqVO pageReqVO) {
        PageResult<Nurse_recordDO> pageResult = nurse_recordService.getNurse_recordPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, Nurse_recordRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出护理记录 Excel")
    @PreAuthorize("@ss.hasPermission('yyzx:nurse_record:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportNurse_recordExcel(@Valid Nurse_recordPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<Nurse_recordDO> list = nurse_recordService.getNurse_recordPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "护理记录.xls", "数据", Nurse_recordRespVO.class,
                        BeanUtils.toBean(list, Nurse_recordRespVO.class));
    }

}